package 掘金.饭馆菜品选择问题;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static long solution(String s, int[] a, int m, int k) {
        // write code here
        int[][] t = new int[a.length][2];
        for (int i = 0; i < a.length; i++) {
            t[i][0] = a[i];
            t[i][1] = s.charAt(i) - '0';
        }
        Arrays.sort(t, Comparator.comparingInt(o -> o[0]));


        int n = s.length();
        int cost = 0;
        for (int i = 0; i < n; i++) {
            if (t[i][1] == 1) {
                if(m>0) {
                    cost += t[i][0];
                    m--;
                    k--;
                }
            }else{
                cost += t[i][0];
                k--;
            }
            if(k==0){
                return cost;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(solution("110100101", new int[]{5,7,13,8,2,1,9,15,17}, 14, 4) == 15);
    }
}